package com.hualan.sfzy.controller.mind;
import com.hualan.sfzy.entity.mind.MindKnowledge;
import com.hualan.sfzy.service.mind.MindKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("mindKnowledge")
public class MindKnowledgeController {
    @Autowired
    private MindKnowledgeService mindKnowledgeService;

    // 新增资源：正确使用POST + @RequestBody
    @PostMapping
    public int insert(@RequestBody MindKnowledge mindKnowledge) {
        return mindKnowledgeService.add(mindKnowledge);
    }

    // 更新资源：正确使用PUT + @RequestBody
    @PutMapping
    public int update(@RequestBody MindKnowledge mindKnowledge) {
        return mindKnowledgeService.edit(mindKnowledge);
    }

    // 删除单个资源：路径参数用@PathVariable
    @DeleteMapping("/{id}")
    public int delete(@PathVariable Integer id) {
        return mindKnowledgeService.remove(id);
    }

    // 批量删除：正确接收请求参数数组
    @DeleteMapping()
    public int deleteBatch(@RequestParam Integer[] ids) {
        return mindKnowledgeService.removeBatch(ids);
    }

    // 查询列表：GET请求无需@RequestBody，传入查询条件
    @GetMapping
    public List<MindKnowledge> select(MindKnowledge mindKnowledge) {
        return mindKnowledgeService.find();
    }

    // 查询单个资源：路径参数用@PathVariable
    @GetMapping("/{id}")
    public MindKnowledge selectById(@PathVariable Integer id) {
        return mindKnowledgeService.findById(id);
    }

    // 分页查询：正确接收分页参数和查询条件
    @GetMapping("/page")
    public Map<String, Object> findByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                          @RequestParam(defaultValue = "10") Integer pageSize,
                                          MindKnowledge mindKnowledge) {
        return mindKnowledgeService.findByPage(pageNum, pageSize, mindKnowledge);
    }
}